import React, { useState } from 'react';
import { Form, Input, Button, Checkbox, message } from 'antd';
import { UserOutlined, LockOutlined, SafetyCertificateOutlined } from '@ant-design/icons';
import { useNavigate } from 'react-router-dom';
import './index.less';

const Login: React.FC = () => {
  const [loading, setLoading] = useState(false);
  const navigate = useNavigate();

  const onFinish = (values: any) => {
    setLoading(true);
    console.log('登录表单提交:', values);
    
    // 模拟登录请求
    setTimeout(() => {
      setLoading(false);
      message.success('登录成功');
      navigate('/dashboard');
    }, 1500);
  };

  return (
    <div className="login-container">
      <div className="background-effect">
        <div className="grid-overlay"></div>
        <div className="particles-container">
          {[...Array(20)].map((_, i) => (
            <div className="particle" key={i} style={{
              top: `${Math.random() * 100}%`,
              left: `${Math.random() * 100}%`,
              animationDelay: `${Math.random() * 5}s`,
              width: `${Math.random() * 2 + 1}px`,
              height: `${Math.random() * 2 + 1}px`,
              animationDuration: `${Math.random() * 10 + 10}s`
            }}></div>
          ))}
        </div>
        <div className="circle-glow"></div>
      </div>
      
      <div className="login-content">
        <div className="login-header">
          <div className="logo-container">
            <div className="logo-icon"></div>
            <div className="system-name">MiaoMiao Admin</div>
          </div>
          <div className="system-desc">科技感设计风格的后台管理系统</div>
        </div>
        
        <div className="login-form-container">
          <div className="form-title">系统登录</div>
          
          <Form
            name="login-form"
            className="login-form"
            initialValues={{ remember: true }}
            onFinish={onFinish}
          >
            <Form.Item
              name="username"
              rules={[{ required: true, message: '请输入用户名' }]}
            >
              <Input 
                prefix={<UserOutlined className="site-form-item-icon" />} 
                placeholder="用户名" 
                className="tech-input"
              />
            </Form.Item>
            
            <Form.Item
              name="password"
              rules={[{ required: true, message: '请输入密码' }]}
            >
              <Input.Password
                prefix={<LockOutlined className="site-form-item-icon" />}
                placeholder="密码"
                className="tech-input"
              />
            </Form.Item>
            
            <Form.Item
              name="captcha"
              rules={[{ required: true, message: '请输入验证码' }]}
            >
              <div className="captcha-container">
                <Input
                  prefix={<SafetyCertificateOutlined className="site-form-item-icon" />}
                  placeholder="验证码"
                  className="tech-input captcha-input"
                />
                <div className="captcha-img" onClick={() => message.info('点击刷新验证码')}>
                  <img src="https://via.placeholder.com/100x40/071630/a3daff?text=CAPTCHA" alt="验证码" />
                </div>
              </div>
            </Form.Item>
            
            <Form.Item>
              <Form.Item name="remember" valuePropName="checked" noStyle>
                <Checkbox className="remember-me">记住我</Checkbox>
              </Form.Item>
              
              <a className="login-form-forgot" href="#">
                忘记密码
              </a>
            </Form.Item>
            
            <Form.Item>
              <Button 
                type="primary" 
                htmlType="submit" 
                className="login-form-button"
                loading={loading}
              >
                登录
              </Button>
            </Form.Item>
          </Form>
        </div>
      </div>
    </div>
  );
};

export default Login; 